/**
 * 
 */
package net.kaizhong.excel.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.FastDateFormat;

import net.kaizhong.excel.Converter;

/**
 * @author huqifeng
 *
 */
public class DateConverter implements Converter {

    /**
     * 
     */
    public DateConverter() {

    }

    @Override
    public String convertOut(Object srcValue) {
        String destValue = "";
        if (null != srcValue) {
            FastDateFormat fdf = FastDateFormat.getInstance("yyyy-MM-dd");

            if (srcValue instanceof Date) {
                destValue = fdf.format(srcValue);
            }
        }
        return destValue;
    }

    @Override
    public Object convertIn(String srcValue) {
        Date destValue = null;
        if (StringUtils.isNotBlank(srcValue)) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            try {
                destValue = format.parse(srcValue);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        return destValue;
    }

}
